import React, { Component } from 'react'
import {
    Modal,
} from 'react-bootstrap';

import { getHost, UpdateFile } from '../../../core/utils/fetch';

class BatchEdit extends Component {

    static defaultProps = {
        isShow: false,
    };

    state = {
        isShow: this.props.isShow,
    };

    componentWillReceiveProps = (props) => {
        this.setState({ isShow: props.isShow });
    };

    render() {
        return (
            <Modal show={this.state.isShow} keyboard={true} enforceFocus={false}>
                <Modal.Header>
                    <Modal.Title>导入文件</Modal.Title>
                </Modal.Header>
                <Modal.Body>
                    <button type="button" className="btn btn-success" onClick={this._onDownload}>模板下载</button>
                    <form>
                        <div className="form-group">
                            <label style={{ "width": "100%", "marginTop": "30px" }}>
                                <input id="carFile" type="file" className="form-control" readOnly={true} style={{ "float": "left", "width": "300px" }} />
                            </label>
                        </div>
                    </form>
                </Modal.Body>
                <Modal.Footer>
                    <button type="button" className="btn btn-default" onClick={this._close}>关闭</button>
                    <button type="button" className="btn btn-primary" onClick={this._save}>导入</button>
                </Modal.Footer>
            </Modal>
        )
    }

    _onDownload = () => {
        window.open(getHost() + '/spi/custInvest/download');
    };

    _close = () => {
        this.setState({ isShow: false });
    };

    _save = (id) => {
        UpdateFile(window.jQuery('#carFile')[0], () => {
            this._close();
            this.props.onEdit();
        }, '/spi/custInvest/uploadCar');
    };
}

export default BatchEdit